package tothreedesignmodel.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lzhphantom
 * @description
 * @date 创建于 18:04 2020/8/1
 * @modified
 */
public class Composite implements Component {
    private List<Component> children = new ArrayList<>();

    @Override
    public void add(Component c) {
        children.add(c);
    }

    @Override
    public void remove(Component c) {
        children.remove(c);
    }

    @Override
    public Component getChild(int i) {
        return children.get(i);
    }

    @Override
    public void operation() {
        children.forEach(Component::operation);
    }
}
